package com.viphuli.app.tool.fragment;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.OnClick;

import com.loopj.android.http.RequestParams;
import com.viphuli.app.tool.R;
import com.viphuli.app.tool.adapter.MemberAdapter;
import com.viphuli.app.tool.bean.part.AccountUser;
import com.viphuli.app.tool.common.AccessTokenKeeper;
import com.viphuli.app.tool.common.MyPageHelper;
import com.viphuli.app.tool.handler.MyBaseHttpResponseHandler.HandlerType;
import com.viphuli.app.tool.http.ApiRequest;

/**
 * 成员列表 
 * 
 * @author li.li
 *
 */
public class CircleMemberFragment extends BaseProgressFragment{

	@Bind(R.id.id_circle_member_girdview)
	protected GridView memberGirdView;

	private MemberAdapter adapter;

	private List<AccountUser> userList = new ArrayList<AccountUser>();
	
	private boolean isEdit;

	@Override
	protected int obtainContentRes() {
		return R.layout.frag_member;
	}

	@Override
	protected void initParams() {
		//解析参数
		Bundle args = getArguments();
	}

	@Override
	protected void initView() {

	}

	@Override
	protected void initData() {
		
		initRequest(HandlerType.loading);
	}
	
	@Override
	protected void initRequest(HandlerType handlerType) {
		AccessTokenKeeper token = AccessTokenKeeper.readAccessToken(getActivity());

		if (token.isLogin()) {

			RequestParams params = new RequestParams();
			params.put("circle_id", token.getUser().circleId());
			ApiRequest.circleMember.request(this, params);

		}
	}

	@OnClick(R.id.id_circle_member_edit)
	public void clickEdit(TextView view) {

		String content = view.getText().toString();

		if ("编辑".equals(content)) {

			view.setText("完成");

			setEdit(true);
			adapter.notifyDataSetChanged();

		} else if ("完成".equals(content)) {

			view.setText("编辑");

			setEdit(false);
			adapter.notifyDataSetChanged();

		}

	}

	public GridView getMemberGirdView() {
		return memberGirdView;
	}

	public void setAdapter(MemberAdapter adapter) {
		this.adapter = adapter;
	}
	
	public MemberAdapter getAdapter() {
		return adapter;
	}

	public List<AccountUser> getUserList() {
		return userList;
	}
	
	public void setEdit(boolean isEdit) {
		this.isEdit = isEdit;
	}

	public boolean isEdit() {
		return isEdit;
	}

	public static void go(Activity act) {
		MyPageHelper.circleMember.showMyPage(act);
	}

}
